package com.handpay.zztong.hp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.handpay.zztong.hp.R;
import com.handpay.zztong.hp.accountcenter.model.BankProvince;

import java.util.ArrayList;
import java.util.List;

public class ProvinceAdapter extends BaseAdapter {
	List<BankProvince> mBankProvinces = new ArrayList<BankProvince>(100);
	LayoutInflater mLI = null;
	Context hpcontext;
	public ProvinceAdapter(Context context) {
		mLI = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
		hpcontext = context;
	}
	
	public synchronized void refreshBankProvinces(List<BankProvince> bankProvinces) {
		mBankProvinces.clear();
		BankProvince pleaseSelectBank = new BankProvince();
		pleaseSelectBank.setBankProvinceName(hpcontext.getString(R.string.please_select_Province));
		pleaseSelectBank.setBankProvinceId("");
		bankProvinces.add(pleaseSelectBank);
		mBankProvinces.addAll(bankProvinces);
		this.notifyDataSetChanged();
	}
	public synchronized void clearBankProvinces() {
		mBankProvinces.clear();
	}
	@Override
	public int getCount() {
		return mBankProvinces.size() > 0 ?  mBankProvinces.size() - 1:0;
	}

	@Override
	public Object getItem(int position) {
		return mBankProvinces.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
	// 用于其他
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {

		View container = null;
		if(null == convertView) {
			convertView = mLI.inflate(R.layout.bank_item, null);
		}
		container = convertView;
		container.findViewById(R.id.ivBankLogo).setVisibility(View.GONE);
		((TextView)container.findViewById(R.id.tvBankName)).setText(mBankProvinces.get(position).getBankProvinceName());
		container.findViewById(R.id.ivChecked).setVisibility(View.GONE);
		return container;	 
   }
    // 用于spinner
	@Override
	public View getDropDownView(int position, View convertView, ViewGroup parent) {
		View container = null;
		if(null == convertView) {
			convertView = mLI.inflate(R.layout.bank_item, null);
		}
		container = convertView;
		container.findViewById(R.id.ivBankLogo).setVisibility(View.GONE);
		TextView tvbankname = (TextView)container.findViewById(R.id.tvBankName);
		tvbankname.setText(mBankProvinces.get(position).getBankProvinceName());
		tvbankname.setTextColor(hpcontext.getResources().getColorStateList(R.color.keyboardnumber));
		container.findViewById(R.id.ivChecked).setVisibility(View.GONE);
		return container;
	}
}
